/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 13754
 * @create 2023/11/29
 * @since 1.0.0
 */
package com.mengniu.commerce.collect.third.request;

import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.collect.third.WeiMengApi;
import com.mengniu.commerce.collect.third.response.item.GoodsInfoModel;
import com.mengniu.commerce.collect.third.response.item.GoodsListResponse;
import com.mengniu.commerce.collect.util.RestTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微盟商品数据请求
 * @author 13754
 * @Date 2023/11/29 11:55
 * @Version 1.0.0
 */
@Service
public class IWeiMengGoodsRequest {

    private static String baseUrl ="https://dopen.weimob.com";

    private static String vid ="6001451595805";

    @Autowired
    RestTemplateUtil restTemplateUtil;

    /**
     * 分页查询商品列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    public GoodsListResponse getGoodsList(int pageNum,int pageSize,String token){

        String url =baseUrl+ WeiMengApi.WM_GETGOODSLIST;
        JSONObject js = new JSONObject();
        js.put("pageNum",pageNum);
        js.put("pageSize",pageSize);
        JSONObject js2 = new JSONObject();
        js2.put("vid",vid);
        js.put("basicInfo",js2);
        String result = restTemplateUtil.doPost(js, url,token);
        return  JSONObject.parseObject(result,GoodsListResponse.class);
    }

    /**
     * 查询商品详情
     * @param goodsId
     * @return
     */
    public GoodsInfoModel getGoodsInfoById(Long goodsId, String token){
        String url =baseUrl+ WeiMengApi.WM_GOODSINFO;
        JSONObject js = new JSONObject();
        js.put("vid",vid);
        JSONObject js2 = new JSONObject();
        js2.put("basicInfo",js);
        js2.put("goodsId",goodsId);
        String result = restTemplateUtil.doPost(js2, url,token);
        return  JSONObject.parseObject(result,GoodsInfoModel.class);
    }

}
